package RegExp;

import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

/**
 * Created with IntelliJ IDEA.
 * User: Ratuil
 * Date: 17.03.13
 * Time: 18:38
 * To change this template use File | Settings | File Templates.
 */
public class DateParse {
    public static void main(String[] args) {
        new DateParse().run();
    }
    public void run(){
        Pattern p=null;
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter date in format yyyy-mm-dd:");
        String str=null;
        try{
            str=sc.nextLine();
            p=Pattern.compile("[0-9]{4}" +                //day
                    "-((0[1-9])|(1[0-2]))" +              //month
                    "-((0[1-9])|([1-2][0-9])|(3[0-1]))"); //year
        }catch (PatternSyntaxException e){
            System.out.println("Syntax error in pattern");
            System.exit(1);
        }catch (Exception e){
            System.out.println("Something went wrong");
            System.exit(1);
        }
        Matcher m=p.matcher(str);
        if(m.matches()) System.out.println("true".toUpperCase());
        else System.out.println("false".toUpperCase());
    }
}
